<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link href="cpip.css" rel="stylesheet" type="text/css" />
    <title>File: /Users/paulross/dev/Python-3.6.2/Include/floatobject.h</title>
  </head>
  <body>
    <h1>File: /Users/paulross/dev/Python-3.6.2/Include/floatobject.h</h1>
    <p>Green shading in the line number column
means the source is part of the translation unit, red means it is conditionally excluded.
Highlighted line numbers link to the translation unit page. Highlighted macros link to
the macro page.</p>
    <pre><a name="1" /><span class="True">       1:</span> 
<a name="2" /><span class="True">       2:</span> <span class="k">/* Float object interface */</span>
<a name="3" /><span class="True">       3:</span> 
<a name="4" /><span class="True">       4:</span> <span class="k">/*</span>
<a name="5" /><span class="True">       5:</span> <span class="k">PyFloatObject represents a (double precision) floating point number.</span>
<a name="6" /><span class="True">       6:</span> <span class="k">*/</span>
<a name="7" /><span class="True">       7:</span> 
<a name="8" /><span class="True">       8:</span> <span class="f">#</span><span class="n">ifndef</span> <a href="macros_noref.html#_UHlfRkxPQVRPQkpFQ1RfSF8w"><span class="b">Py_FLOATOBJECT_H</span></a>
<a name="9" /><span class="True">       9:</span> <span class="f">#</span><span class="n">define</span> <a href="macros_noref.html#_UHlfRkxPQVRPQkpFQ1RfSF8w"><span class="b">Py_FLOATOBJECT_H</span></a>
<a name="10" /><span class="False">      10:</span> <span class="f">#</span><span class="n">ifdef</span> <span class="b">__cplusplus</span>
<a name="11" /><span class="False">      11:</span> <span class="m">extern</span> <span class="e">&quot;C&quot;</span> <span class="f">{</span>
<a name="12" /><span class="True">      12:</span> <span class="f">#</span><span class="n">endif</span>
<a name="13" /><span class="True">      13:</span> 
<a name="14" /><span class="True">      14:</span> <span class="f">#</span><span class="n">ifndef</span> <span class="b">Py_LIMITED_API</span>
<a name="15" /><span class="True">      15:</span> <span class="m">typedef</span> <span class="m">struct</span> <span class="f">{</span>
<a name="16" /><span class="True">      16:</span>     <a href="macros_ref.html#_UHlPYmplY3RfSEVBRF8w"><span class="b">PyObject_HEAD</span></a>
<a name="17" /><span class="True">      17:</span>     <span class="m">double</span> <span class="b">ob_fval</span><span class="f">;</span>
<a name="18" /><span class="True">      18:</span> <span class="f">}</span> <span class="b">PyFloatObject</span><span class="f">;</span>
<a name="19" /><span class="True">      19:</span> <span class="f">#</span><span class="n">endif</span>
<a name="20" /><span class="True">      20:</span> 
<a name="21" /><span class="True">      21:</span> <a href="macros_ref.html#_UHlBUElfREFUQV8w"><span class="b">PyAPI_DATA</span></a><span class="f">(</span><span class="b">PyTypeObject</span><span class="f">)</span> <span class="b">PyFloat_Type</span><span class="f">;</span>
<a name="22" /><span class="True">      22:</span> 
<a name="23" /><span class="True">      23:</span> <span class="f">#</span><span class="n">define</span> <a href="macros_noref.html#_UHlGbG9hdF9DaGVja18w"><span class="b">PyFloat_Check</span></a><span class="f">(</span><span class="b">op</span><span class="f">)</span> <a href="macros_ref.html#_UHlPYmplY3RfVHlwZUNoZWNrXzA_"><span class="b">PyObject_TypeCheck</span></a><span class="f">(</span><span class="b">op</span><span class="f">,</span> <span class="f">&amp;</span><span class="b">PyFloat_Type</span><span class="f">)</span>
<a name="24" /><span class="True">      24:</span> <span class="f">#</span><span class="n">define</span> <a href="macros_noref.html#_UHlGbG9hdF9DaGVja0V4YWN0XzA_"><span class="b">PyFloat_CheckExact</span></a><span class="f">(</span><span class="b">op</span><span class="f">)</span> <span class="f">(</span><a href="macros_ref.html#_UHlfVFlQRV8w"><span class="b">Py_TYPE</span></a><span class="f">(</span><span class="b">op</span><span class="f">)</span> <span class="f">==</span> <span class="f">&amp;</span><span class="b">PyFloat_Type</span><span class="f">)</span>
<a name="25" /><span class="True">      25:</span> 
<a name="26" /><span class="True">      26:</span> <span class="f">#</span><span class="n">ifdef</span> <a href="macros_ref.html#_UHlfTkFOXzA_"><span class="b">Py_NAN</span></a>
<a name="27" /><span class="True">      27:</span> <span class="f">#</span><span class="n">define</span> <a href="macros_noref.html#_UHlfUkVUVVJOX05BTl8w"><span class="b">Py_RETURN_NAN</span></a> <span class="m">return</span> <span class="b">PyFloat_FromDouble</span><span class="f">(</span><a href="macros_ref.html#_UHlfTkFOXzA_"><span class="b">Py_NAN</span></a><span class="f">)</span>
<a name="28" /><span class="True">      28:</span> <span class="f">#</span><span class="n">endif</span>
<a name="29" /><span class="True">      29:</span> 
<a name="30" /><span class="True">      30:</span> <span class="f">#</span><span class="n">define</span> <a href="macros_noref.html#_UHlfUkVUVVJOX0lORl8w"><span class="b">Py_RETURN_INF</span></a><span class="f">(</span><span class="b">sign</span><span class="f">)</span> <span class="m">do</span>                     \
<a name="31" /><span class="True">      31:</span>     <span class="m">if</span> <span class="f">(</span><span class="b">copysign</span><span class="f">(</span><span class="c">1.</span><span class="f">,</span> <span class="b">sign</span><span class="f">)</span> <span class="f">==</span> <span class="c">1.</span><span class="f">)</span> <span class="f">{</span>                \
<a name="32" /><span class="True">      32:</span>         <span class="m">return</span> <span class="b">PyFloat_FromDouble</span><span class="f">(</span><a href="macros_noref.html#_UHlfSFVHRV9WQUxfMA__"><span class="b">Py_HUGE_VAL</span></a><span class="f">)</span><span class="f">;</span>    \
<a name="33" /><span class="True">      33:</span>     <span class="f">}</span> <span class="m">else</span> <span class="f">{</span>                        \
<a name="34" /><span class="True">      34:</span>         <span class="m">return</span> <span class="b">PyFloat_FromDouble</span><span class="f">(</span><span class="f">-</span><a href="macros_noref.html#_UHlfSFVHRV9WQUxfMA__"><span class="b">Py_HUGE_VAL</span></a><span class="f">)</span><span class="f">;</span>   \
<a name="35" /><span class="True">      35:</span>     <span class="f">}</span> <span class="m">while</span><span class="f">(</span><span class="c">0</span><span class="f">)</span>
<a name="36" /><span class="True">      36:</span> 
<a name="37" /><span class="True">      37:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">double</span><span class="f">)</span> <span class="b">PyFloat_GetMax</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="38" /><span class="True">      38:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">double</span><span class="f">)</span> <span class="b">PyFloat_GetMin</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="39" /><span class="True">      39:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="b">PyObject</span> <span class="f">*</span><span class="f">)</span> <span class="b">PyFloat_GetInfo</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="40" /><span class="True">      40:</span> 
<a name="41" /><span class="True">      41:</span> <span class="k">/* Return Python float from string PyObject. */</span>
<a name="42" /><span class="True">      42:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="b">PyObject</span> <span class="f">*</span><span class="f">)</span> <span class="b">PyFloat_FromString</span><span class="f">(</span><span class="b">PyObject</span><span class="f">*</span><span class="f">)</span><span class="f">;</span>
<a name="43" /><span class="True">      43:</span> 
<a name="44" /><span class="True">      44:</span> <span class="k">/* Return Python float from C double. */</span>
<a name="45" /><span class="True">      45:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="b">PyObject</span> <span class="f">*</span><span class="f">)</span> <span class="b">PyFloat_FromDouble</span><span class="f">(</span><span class="m">double</span><span class="f">)</span><span class="f">;</span>
<a name="46" /><span class="True">      46:</span> 
<a name="47" /><span class="True">      47:</span> <span class="k">/* Extract C double from Python float.  The macro version trades safety for</span>
<a name="48" /><span class="True">      48:</span> <span class="k">   speed. */</span>
<a name="49" /><span class="True">      49:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">double</span><span class="f">)</span> <span class="b">PyFloat_AsDouble</span><span class="f">(</span><span class="b">PyObject</span> <span class="f">*</span><span class="f">)</span><span class="f">;</span>
<a name="50" /><span class="True">      50:</span> <span class="f">#</span><span class="n">ifndef</span> <span class="b">Py_LIMITED_API</span>
<a name="51" /><span class="True">      51:</span> <span class="f">#</span><span class="n">define</span> <a href="macros_noref.html#_UHlGbG9hdF9BU19ET1VCTEVfMA__"><span class="b">PyFloat_AS_DOUBLE</span></a><span class="f">(</span><span class="b">op</span><span class="f">)</span> <span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="b">PyFloatObject</span> <span class="f">*</span><span class="f">)</span><span class="f">(</span><span class="b">op</span><span class="f">)</span><span class="f">)</span><span class="f">-&gt;</span><span class="b">ob_fval</span><span class="f">)</span>
<a name="52" /><span class="True">      52:</span> <span class="f">#</span><span class="n">endif</span>
<a name="53" /><span class="True">      53:</span> 
<a name="54" /><span class="True">      54:</span> <span class="f">#</span><span class="n">ifndef</span> <span class="b">Py_LIMITED_API</span>
<a name="55" /><span class="True">      55:</span> <span class="k">/* _PyFloat_{Pack,Unpack}{4,8}</span>
<a name="56" /><span class="True">      56:</span> <span class="k"> *</span>
<a name="57" /><span class="True">      57:</span> <span class="k"> * The struct and pickle (at least) modules need an efficient platform-</span>
<a name="58" /><span class="True">      58:</span> <span class="k"> * independent way to store floating-point values as byte strings.</span>
<a name="59" /><span class="True">      59:</span> <span class="k"> * The Pack routines produce a string from a C double, and the Unpack</span>
<a name="60" /><span class="True">      60:</span> <span class="k"> * routines produce a C double from such a string.  The suffix (4 or 8)</span>
<a name="61" /><span class="True">      61:</span> <span class="k"> * specifies the number of bytes in the string.</span>
<a name="62" /><span class="True">      62:</span> <span class="k"> *</span>
<a name="63" /><span class="True">      63:</span> <span class="k"> * On platforms that appear to use (see _PyFloat_Init()) IEEE-754 formats</span>
<a name="64" /><span class="True">      64:</span> <span class="k"> * these functions work by copying bits.  On other platforms, the formats the</span>
<a name="65" /><span class="True">      65:</span> <span class="k"> * 4- byte format is identical to the IEEE-754 single precision format, and</span>
<a name="66" /><span class="True">      66:</span> <span class="k"> * the 8-byte format to the IEEE-754 double precision format, although the</span>
<a name="67" /><span class="True">      67:</span> <span class="k"> * packing of INFs and NaNs (if such things exist on the platform) isn&apos;t</span>
<a name="68" /><span class="True">      68:</span> <span class="k"> * handled correctly, and attempting to unpack a string containing an IEEE</span>
<a name="69" /><span class="True">      69:</span> <span class="k"> * INF or NaN will raise an exception.</span>
<a name="70" /><span class="True">      70:</span> <span class="k"> *</span>
<a name="71" /><span class="True">      71:</span> <span class="k"> * On non-IEEE platforms with more precision, or larger dynamic range, than</span>
<a name="72" /><span class="True">      72:</span> <span class="k"> * 754 supports, not all values can be packed; on non-IEEE platforms with less</span>
<a name="73" /><span class="True">      73:</span> <span class="k"> * precision, or smaller dynamic range, not all values can be unpacked.  What</span>
<a name="74" /><span class="True">      74:</span> <span class="k"> * happens in such cases is partly accidental (alas).</span>
<a name="75" /><span class="True">      75:</span> <span class="k"> */</span>
<a name="76" /><span class="True">      76:</span> 
<a name="77" /><span class="True">      77:</span> <span class="k">/* The pack routines write 2, 4 or 8 bytes, starting at p.  le is a bool</span>
<a name="78" /><span class="True">      78:</span> <span class="k"> * argument, true if you want the string in little-endian format (exponent</span>
<a name="79" /><span class="True">      79:</span> <span class="k"> * last, at p+1, p+3 or p+7), false if you want big-endian format (exponent</span>
<a name="80" /><span class="True">      80:</span> <span class="k"> * first, at p).</span>
<a name="81" /><span class="True">      81:</span> <span class="k"> * Return value:  0 if all is OK, -1 if error (and an exception is</span>
<a name="82" /><span class="True">      82:</span> <span class="k"> * set, most likely OverflowError).</span>
<a name="83" /><span class="True">      83:</span> <span class="k"> * There are two problems on non-IEEE platforms:</span>
<a name="84" /><span class="True">      84:</span> <span class="k"> * 1):  What this does is undefined if x is a NaN or infinity.</span>
<a name="85" /><span class="True">      85:</span> <span class="k"> * 2):  -0.0 and +0.0 produce the same string.</span>
<a name="86" /><span class="True">      86:</span> <span class="k"> */</span>
<a name="87" /><span class="True">      87:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">int</span><span class="f">)</span> <span class="b">_PyFloat_Pack2</span><span class="f">(</span><span class="m">double</span> <span class="b">x</span><span class="f">,</span> <span class="m">unsigned</span> <span class="m">char</span> <span class="f">*</span><span class="b">p</span><span class="f">,</span> <span class="m">int</span> <span class="b">le</span><span class="f">)</span><span class="f">;</span>
<a name="88" /><span class="True">      88:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">int</span><span class="f">)</span> <span class="b">_PyFloat_Pack4</span><span class="f">(</span><span class="m">double</span> <span class="b">x</span><span class="f">,</span> <span class="m">unsigned</span> <span class="m">char</span> <span class="f">*</span><span class="b">p</span><span class="f">,</span> <span class="m">int</span> <span class="b">le</span><span class="f">)</span><span class="f">;</span>
<a name="89" /><span class="True">      89:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">int</span><span class="f">)</span> <span class="b">_PyFloat_Pack8</span><span class="f">(</span><span class="m">double</span> <span class="b">x</span><span class="f">,</span> <span class="m">unsigned</span> <span class="m">char</span> <span class="f">*</span><span class="b">p</span><span class="f">,</span> <span class="m">int</span> <span class="b">le</span><span class="f">)</span><span class="f">;</span>
<a name="90" /><span class="True">      90:</span> 
<a name="91" /><span class="True">      91:</span> <span class="k">/* Needed for the old way for marshal to store a floating point number.</span>
<a name="92" /><span class="True">      92:</span> <span class="k">   Returns the string length copied into p, -1 on error.</span>
<a name="93" /><span class="True">      93:</span> <span class="k"> */</span>
<a name="94" /><span class="True">      94:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">int</span><span class="f">)</span> <span class="b">_PyFloat_Repr</span><span class="f">(</span><span class="m">double</span> <span class="b">x</span><span class="f">,</span> <span class="m">char</span> <span class="f">*</span><span class="b">p</span><span class="f">,</span> <span class="b">size_t</span> <span class="b">len</span><span class="f">)</span><span class="f">;</span>
<a name="95" /><span class="True">      95:</span> 
<a name="96" /><span class="True">      96:</span> <span class="k">/* Used to get the important decimal digits of a double */</span>
<a name="97" /><span class="True">      97:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">int</span><span class="f">)</span> <span class="b">_PyFloat_Digits</span><span class="f">(</span><span class="m">char</span> <span class="f">*</span><span class="b">buf</span><span class="f">,</span> <span class="m">double</span> <span class="b">v</span><span class="f">,</span> <span class="m">int</span> <span class="f">*</span><span class="b">signum</span><span class="f">)</span><span class="f">;</span>
<a name="98" /><span class="True">      98:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">void</span><span class="f">)</span> <span class="b">_PyFloat_DigitsInit</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="99" /><span class="True">      99:</span> 
<a name="100" /><span class="True">     100:</span> <span class="k">/* The unpack routines read 2, 4 or 8 bytes, starting at p.  le is a bool</span>
<a name="101" /><span class="True">     101:</span> <span class="k"> * argument, true if the string is in little-endian format (exponent</span>
<a name="102" /><span class="True">     102:</span> <span class="k"> * last, at p+1, p+3 or p+7), false if big-endian (exponent first, at p).</span>
<a name="103" /><span class="True">     103:</span> <span class="k"> * Return value:  The unpacked double.  On error, this is -1.0 and</span>
<a name="104" /><span class="True">     104:</span> <span class="k"> * PyErr_Occurred() is true (and an exception is set, most likely</span>
<a name="105" /><span class="True">     105:</span> <span class="k"> * OverflowError).  Note that on a non-IEEE platform this will refuse</span>
<a name="106" /><span class="True">     106:</span> <span class="k"> * to unpack a string that represents a NaN or infinity.</span>
<a name="107" /><span class="True">     107:</span> <span class="k"> */</span>
<a name="108" /><span class="True">     108:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">double</span><span class="f">)</span> <span class="b">_PyFloat_Unpack2</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">char</span> <span class="f">*</span><span class="b">p</span><span class="f">,</span> <span class="m">int</span> <span class="b">le</span><span class="f">)</span><span class="f">;</span>
<a name="109" /><span class="True">     109:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">double</span><span class="f">)</span> <span class="b">_PyFloat_Unpack4</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">char</span> <span class="f">*</span><span class="b">p</span><span class="f">,</span> <span class="m">int</span> <span class="b">le</span><span class="f">)</span><span class="f">;</span>
<a name="110" /><span class="True">     110:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">double</span><span class="f">)</span> <span class="b">_PyFloat_Unpack8</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">char</span> <span class="f">*</span><span class="b">p</span><span class="f">,</span> <span class="m">int</span> <span class="b">le</span><span class="f">)</span><span class="f">;</span>
<a name="111" /><span class="True">     111:</span> 
<a name="112" /><span class="True">     112:</span> <span class="k">/* free list api */</span>
<a name="113" /><span class="True">     113:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">int</span><span class="f">)</span> <span class="b">PyFloat_ClearFreeList</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="114" /><span class="True">     114:</span> 
<a name="115" /><span class="True">     115:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">void</span><span class="f">)</span> <span class="b">_PyFloat_DebugMallocStats</span><span class="f">(</span><span class="b">FILE</span><span class="f">*</span> <span class="b">out</span><span class="f">)</span><span class="f">;</span>
<a name="116" /><span class="True">     116:</span> 
<a name="117" /><span class="True">     117:</span> <span class="k">/* Format the object based on the format_spec, as defined in PEP 3101</span>
<a name="118" /><span class="True">     118:</span> <span class="k">   (Advanced String Formatting). */</span>
<a name="119" /><span class="True">     119:</span> <a href="macros_ref.html#_UHlBUElfRlVOQ18w"><span class="b">PyAPI_FUNC</span></a><span class="f">(</span><span class="m">int</span><span class="f">)</span> <span class="b">_PyFloat_FormatAdvancedWriter</span><span class="f">(</span>
<a name="120" /><span class="True">     120:</span>     <span class="b">_PyUnicodeWriter</span> <span class="f">*</span><span class="b">writer</span><span class="f">,</span>
<a name="121" /><span class="True">     121:</span>     <span class="b">PyObject</span> <span class="f">*</span><span class="b">obj</span><span class="f">,</span>
<a name="122" /><span class="True">     122:</span>     <span class="b">PyObject</span> <span class="f">*</span><span class="b">format_spec</span><span class="f">,</span>
<a name="123" /><span class="True">     123:</span>     <span class="b">Py_ssize_t</span> <span class="b">start</span><span class="f">,</span>
<a name="124" /><span class="True">     124:</span>     <span class="b">Py_ssize_t</span> <span class="b">end</span><span class="f">)</span><span class="f">;</span>
<a name="125" /><span class="True">     125:</span> <span class="f">#</span><span class="n">endif</span> <span class="k">/* Py_LIMITED_API */</span>
<a name="126" /><span class="True">     126:</span> 
<a name="127" /><span class="False">     127:</span> <span class="f">#</span><span class="n">ifdef</span> <span class="b">__cplusplus</span>
<a name="128" /><span class="False">     128:</span> <span class="f">}</span>
<a name="129" /><span class="True">     129:</span> <span class="f">#</span><span class="n">endif</span>
<a name="130" /><span class="True">     130:</span> <span class="f">#</span><span class="n">endif</span> <span class="k">/* !Py_FLOATOBJECT_H */</span>
<a name="131" /><span class="True">     131:</span> </pre>
  </body>
</html>
